#!/bin/bash

echo "🔍 Google OAuth 快速检查"
echo "======================="
echo ""

# 检查.env文件是否存在
if [ ! -f .env ]; then
    echo "❌ .env 文件不存在"
    echo "请创建 .env 文件并添加 Google OAuth 配置"
    echo ""
    echo "示例："
    echo "GOOGLE_CLIENT_ID=your_client_id.apps.googleusercontent.com"
    echo "GOOGLE_CLIENT_SECRET=your_client_secret"
    echo "PORT=3001"
    exit 1
fi

echo "✅ .env 文件存在"

# 检查Google配置
source .env

if [ -z "$GOOGLE_CLIENT_ID" ]; then
    echo "❌ GOOGLE_CLIENT_ID 未设置"
    HAS_ERROR=1
else
    echo "✅ GOOGLE_CLIENT_ID 已设置"
fi

if [ -z "$GOOGLE_CLIENT_SECRET" ]; then
    echo "❌ GOOGLE_CLIENT_SECRET 未设置"
    HAS_ERROR=1
else
    echo "✅ GOOGLE_CLIENT_SECRET 已设置"
fi

PORT=${PORT:-3001}
echo "📍 服务器端口: $PORT"

if [ "$HAS_ERROR" = "1" ]; then
    echo ""
    echo "❌ 配置不完整，请设置缺失的环境变量"
    echo ""
    echo "📖 详细指南："
    echo "- docs/GOOGLE_AUTH_SETUP.md"
    echo "- docs/GOOGLE_OAUTH_REDIRECT_SOLUTION.md"
    exit 1
fi

echo ""
echo "✅ Google OAuth 配置检查通过！"
echo ""
echo "🚀 下一步："
echo "1. 确保在 Google Cloud Console 中配置了授权 JavaScript 来源："
echo "   http://localhost:$PORT"
echo ""
echo "2. 运行以下命令启动服务器并测试："
echo "   npm run test:google"
echo ""
echo "3. 或者手动启动："
echo "   npm run dev"
echo "   然后访问: http://localhost:$PORT/docs/google-auth-test.html" 